package com.metaera.app.ui.adapters;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

public class SimpleFragmentStatePagerAdapter extends FragmentStatePagerAdapter {

    private List<String>   titleList;
    private List<Fragment> mFragmentList;

//    public SimpleFragmentStatePagerAdapter(@NonNull FragmentManager fm) {
//        super(fm, null);
//        titleList = new ArrayList<>();
//        mFragmentList = new ArrayList<>();
//    }

    public SimpleFragmentStatePagerAdapter(@NonNull FragmentManager fm, List<Fragment> fragmentList) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        mFragmentList = fragmentList;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titleList.get(position);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public SimpleFragmentStatePagerAdapter add(Fragment fragment, String title) {
        titleList.add(title);
        mFragmentList.add(fragment);
        return this;
    }

    public SimpleFragmentStatePagerAdapter add(Fragment fragment) {
        mFragmentList.add(fragment);
        return this;
    }


}
